#include "fun.h"


/*prints user help */
int
c_help (void){
  fprintf(stderr,"Use nl2a -h for this help\n");
  fprintf(stderr,"use nl2a -f <dumpfile> <action> for open and analyze saved dump file\n");
  fprintf(stderr,"<action> can be -a,-i,-d,-c: \n");
  fprintf(stderr,"                         -a analyze packets from dumpfile\n");
  fprintf(stderr,"                         -d prints packets from dumpfile to stderr\n");
  fprintf(stderr,"                         -i runs user interface in console \n");
  fprintf(stderr,"                         -c to show all connections between 2 MACs \n");
  return 0;
}

/*ask user to choose from start elements in frame_list */
int
ask_user_c (struct fr_list *fr_start){
  struct fr_list *tmp;
  int input=0,id;

  /*I need to know where start with my list*/  
  if(!fr_start){
	printf("Start address not defined\n");
	return -1;
  }
  else
	tmp=fr_start;

  /*Prints nice data about all elements of frame_list*/
  while (tmp!=NULL){
	printf("\nThis frame number was sent with TCP SYN FLAG set  \n");
	printf("Destination MAC address: %s \n",ether_ntoa((struct ether_addr *)tmp->ether_dhost));
    printf("Source MAC address     : %s \n",ether_ntoa((struct ether_addr *)tmp->ether_shost));
	printf("Destination Port %d Source Port %d \n",ntohs(tmp->th_dport),ntohs(tmp->th_sport));
	printf("If you want to select this frame type %d\n\n",tmp->id);
	id=tmp->id;
	tmp=tmp->n_e;
  }
  /*wait for user to choose*/
  printf("Type number of frame which you want to select:");
  do{
	scanf("%d",&input);
	if(input>id)
	  printf("Number must be lower then %d\n",id);
  }
  while(input>id);

  if(!input)
	return -1;
  
  /*return id of selected element*/
  return input;
 
}

/*ask user to choose from start elements in frame_list */
int
ask_user_m (struct m_list *m_start){
  struct m_list *tmp;
  int input=0,id;

  /*I need to know where start with my list*/  
  if(!m_start){
	printf("Start address not defined\n");
	return -1;
  }
  else
	tmp=m_start;

  /*Prints nice data about all elements of frame_list*/
  while (tmp!=NULL){
	printf("Destination MAC address: %s \n",ether_ntoa((struct ether_addr *)tmp->ether_dhost));
    printf("Source MAC address     : %s \n",ether_ntoa((struct ether_addr *)tmp->ether_shost));
	printf("If you want to select this frame type %d\n\n",tmp->id);
	id=tmp->id;
	tmp=tmp->n_e;
  }
  
  /*wait for user to choose*/
  printf("Type number or 0 if you want to select connections of frame which you want to select: ");
  do{
	scanf("%d",&input);
	if(input>id )
	  printf("Number must be lower or equal then %d\n",id);
  }
  while(input>id);

  if (!input)
	return -1;
  /*return id of selected element*/
  return input;
 
}
